package com.letoken.platform.repo.sss.servie.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.letoken.platform.pub.enums.OtcStatusEnum;
import com.letoken.platform.pub.enums.OtcTypeEnum;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.sss.dao.UserOtcDetailMapper;
import com.letoken.platform.repo.sss.po.UserOtcDetail;
import com.letoken.platform.repo.sss.po.UserOtcTransactionRecord;
import com.letoken.platform.repo.sss.servie.UserOtcDetailService;
import com.letoken.platform.repo.sss.vo.UserOtcTransactionRecordVo;
import com.letoken.platform.repo.utlis.PageDataUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者
 * @since 2024-09-05
 */
@Service
public class UserOtcDetailServiceImpl extends ServiceImpl<UserOtcDetailMapper, UserOtcDetail> implements UserOtcDetailService {



    @Resource
    private UserOtcDetailMapper userOtcDetailMapper;


    public ApiResponse<?> transactionRecordPage(Integer pageNum, Integer pageSize, Integer status) {
        Page<UserOtcTransactionRecord> page = userOtcDetailMapper.page(new Page<>(pageNum, pageSize), status);
        if(!CollectionUtils.isEmpty(page.getRecords())){
            List<UserOtcTransactionRecordVo> vos = new ArrayList<>();
            for (UserOtcTransactionRecord record : page.getRecords()) {
                UserOtcTransactionRecordVo vo = new UserOtcTransactionRecordVo();
                vo.setType(record.getType());
                vo.setTypeDesc(OtcTypeEnum.typeDescMap.get(record.getType()));
                vo.setPrice(record.getPrice());
                vo.setQuantity(record.getQuantity());
                vo.setSum(record.getSum());
                vo.setSellerAccount(record.getSellerAccount());
                vo.setCreateTime(record.getCreateTime());
                vo.setStatus(record.getStatus());
                vo.setStatusDesc(OtcStatusEnum.statusDescMap.get(record.getStatus()));
                vos.add(vo);
            }
            return ApiResponse.create(PageDataUtil.getPageData(page, vos));
        }
        return ApiResponse.create();
    }


}
